package com.gzhryc.shared_device.oem.h5.mng.controllers.sys;

import com.gzhryc.common.StringTools;
import com.gzhryc.common.data.dto.AjaxResult;
import com.gzhryc.common.data.dto.ListResult;
import com.gzhryc.log.dao.db.ManagerVisitRecord;
import com.gzhryc.log.services.ManagerVisitRecordService;
import com.gzhryc.log.services.dto.ManagerVisitRecordSearch;
import com.gzhryc.servlet.DtoConstants;
import com.gzhryc.servlet.WebUtils;
import com.gzhryc.servlet.annotation.Route;
import com.gzhryc.shared_device.oem.h5.mng.WebConstants;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class VisitLogController {

	@Route(value="/sys/log/list.html",method="get")
	public String list(HttpServletRequest request) {
		return "/sys/log/list.html";
	}
	
	@Route("/sys/log/list.data")
	public ListResult<ManagerVisitRecord> listData(HttpServletRequest request){
		ListResult<ManagerVisitRecord> result = new ListResult<ManagerVisitRecord>(DtoConstants.SUCCESS);
		
		ManagerVisitRecordSearch search = WebUtils.getParameter(request,ManagerVisitRecordSearch.class);
		Integer pageNo = WebUtils.getInteger(request,"page",1);
		Integer pageLimit = WebUtils.getInteger(request,"limit", WebConstants.PAGE_LIMIT);
		
		result.getBody().setTotal(ManagerVisitRecordService.self().countBySearch(search));
		List<ManagerVisitRecord> recordList = ManagerVisitRecordService.self().findBySearch(search, pageNo, pageLimit);
		if(recordList != null){
			result.getBody().setData(recordList);
		}
		return result;
	}

	@Route("/sys/log/del.do")
	public AjaxResult delete(HttpServletRequest request) {
		AjaxResult result = new AjaxResult(DtoConstants.EXECUTE_ERROR,"删除失败");
		String str = WebUtils.getString(request, "ids");
		if(StringUtils.isNotBlank(str)) {
			List<Long> ids = StringTools.split2Long(str, ",");
			if(ManagerVisitRecordService.self().deleteByIds(ids)) {
				result.setCode(DtoConstants.SUCCESS,null);
			}
		}
		return result;
	}
}
